package com.tidc.seaservermodel.entity;

import com.tidc.seaservermodel.config.RabbitConstants;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.stereotype.Component;

import java.sql.Timestamp;
import java.io.Serializable;
import java.util.Date;
import java.util.UUID;

/**
 * (RabbitMessageLog)实体类
 *
 * @author makejava
 * @since 2020-10-23 20:34:43
 */
@Data
@NoArgsConstructor
@Accessors(chain = true) //这个注解可以使这个类的set方法返回当前对象
public class RabbitMessageLog implements Serializable {
    private static final long serialVersionUID = -66145300358026170L;

    private Integer id;

    private String msgId;
    /**
     * 数据
     */
    private String data;
    /**
     * 0发送中，1发送成功，2发送失败
     */
    private Integer status;

    private String routeKey;

    private String exchange;
    /**
     * 重试次数
     */
    private Integer count;
    /**
     * 第一次重试时间
     */
    private Timestamp tryTime;

    private Timestamp createTime;

    private Timestamp updateTime;

    public RabbitMessageLog(String data, Integer status, String exchange, String routeKey) {
        this.msgId = UUID.randomUUID().toString();
        this.data = data;
        this.status = status;
        this.count = RabbitConstants.DELIVERING;
        this.routeKey = routeKey;
        this.exchange = exchange;
        this.createTime = new Timestamp(new Date().getTime());
        this.updateTime = new Timestamp(new Date().getTime());
        this.tryTime = new Timestamp(new Date(System.currentTimeMillis() + 1000 * 60 * 10).getTime());
    }

    public static RabbitMessageLog sendEmail(String emailJson) {
        return new RabbitMessageLog(emailJson, 0, RabbitConstants.EMAIl_EXCHANGE_NAME, RabbitConstants.SEND_EMAIl_ROUTING_KEY_NAME);
    }

    public static RabbitMessageLog punishmentExperience(String userTaskJson) {
        return new RabbitMessageLog(userTaskJson, 0, RabbitConstants.EXPERIENCE_EXCHANGE_NAME, RabbitConstants.PUNISHMENT_EXPERIENCE_ROUTING_KEY_NAME);
    }
    public static RabbitMessageLog addExperience(String userTaskJson){
        return new RabbitMessageLog(userTaskJson, 0, RabbitConstants.EXPERIENCE_EXCHANGE_NAME, RabbitConstants.ADD_EXPERIENCE_ROUTING_KEY_NAME);
    }
    public static RabbitMessageLog checkCommitmentOut(String commitmentJson){
        return new RabbitMessageLog(commitmentJson, 0, RabbitConstants.CHECK_EXCHANGE_NAME, RabbitConstants.CHECK_COMMITMENT_OUT_ROUTING_KEY_NAME);
    }
    public static RabbitMessageLog checkClearRabbit(String rabbitJson){
        return new RabbitMessageLog(rabbitJson, 0, RabbitConstants.CHECK_EXCHANGE_NAME, RabbitConstants.CHECK_CLEAR_RABBIT_ROUTING_KEY_NAME);
    }
    public static RabbitMessageLog checkTaskOut(String userTaskJson){
        return new RabbitMessageLog(userTaskJson, 0, RabbitConstants.CHECK_EXCHANGE_NAME, RabbitConstants.CHECK_TASK_OUT_ROUTING_KEY_NAME);
    }
}